package com.lk.lkappearance.service.impl;

import com.lk.lkappearance.common.AbstractBaseService;
import com.lk.lkappearance.mapper.MeterMapper;
import com.lk.lkappearance.model.Meter;
import com.lk.lkappearance.service.MeterService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

public class MeterServiceImpl extends AbstractBaseService implements MeterService {

    @Autowired
    private MeterMapper meterMapper;

    /**
     * @param meter
     * @return
     */
    @Override
    public Map<String, Object> add(Meter meter) {
        try {
            meterMapper.insertSelective(meter);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     * @param meter
     * @return
     */
    @Override
    public Map<String, Object> modify(Meter meter) {
        try {
            meterMapper.updateByPrimaryKeySelective(meter);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     * @param meterId
     * @return
     */
    @Override
    public Map<String, Object> delete(String meterId) {
        try {
            meterMapper.deleteByPrimaryKey(meterId);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    @Override
    public Map<String, Object> selectByPrimaryKey(String meterId) {
        try {
            meterMapper.selectByPrimaryKey(meterId);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    @Override
    public Map<String, Object> getList(Meter meter) {
        try {
            meterMapper.getList(meter);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    @Override
    public Map<String, Object> insertListExcel(List<Meter> meterList) {
        try {
            for (Meter meter:meterList) {
                meterMapper.insertSelective(meter);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    @Override
    public Map<String, Object> exportExcel(Meter meter) {
        try {
            meterMapper.getList(meter);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

}
